package data

import (
	"context"
	"fmt"
	"review-service/internal/conf"
	"review-service/internal/data/mysqlquery"
	"review-service/internal/model/mysqlmodel"

	"github.com/go-kratos/kratos/v2/log"
	"github.com/minio/minio-go/v7"
)

func NewReviewRepo(c *conf.Data, logger log.Logger, db *mysqlquery.Query, minioClient *minio.Client) (*ReviewRepo, func(), error) {

	rep := &ReviewRepo{
		log:   log.NewHelper(logger),
		db:    db,
		minio: minioClient,
	}
	cleanup := func() {
		log.NewHelper(logger).Info("使用闭包，关闭数据库连接")
	}
	return rep, cleanup, nil
}

func (r *ReviewRepo) SaveReviewInfo(ctx context.Context, review *mysqlmodel.ReviewInfo) error {
	err := r.db.ReviewInfo.WithContext(ctx).Create(review)
	fmt.Println(review.ID)
	return err
}
